package com.leetcode.algorithm.y22.m09.w2;

/**
 * 1974. 使用特殊打字机键入单词的最少时间
 * 
 * https://leetcode.cn/problems/minimum-time-to-type-word-using-special-typewriter/
 * 
 * @author jie.deng
 *
 */
class Question1974Solution01 {

	public int minTimeToType(String word) {
		int sum = 0;
		int ch = 'a';
		for (int i = 0; i < word.length(); i++) {
			int diff = Math.abs(word.charAt(i) - ch);
			if (diff < 13) {
				sum += diff;
			} else {
				sum += (26 - diff);
			}
			ch = word.charAt(i);
		}
		return sum + word.length();
	}

}